package com.unitd.base.module.master.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.unitd.base.module.master.pojo.dto.AdvertisingVO;
import com.unitd.base.module.master.mybatis.mapper.AdvertisingMapper;
import com.unitd.base.module.master.pojo.po.AdvertisingPO;
import com.unitd.base.module.master.service.AdvertisingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 广告信息表信息处理的业务逻辑接口实现类
 *
 * @author Advertising
 * @version 1.0
 * @filename AdvertisingServiceImpl.java
 * @copyright www.pactera.com
 * @date 2020-08-13
 */
@Slf4j
@Service
public class AdvertisingServiceImpl extends ServiceImpl<AdvertisingMapper, AdvertisingPO> implements AdvertisingService {

    /**
     * 根据广告位ID获取该位置对应的广告详情
     *
     * @param positionId 广告位ID
     * @return 广告位信息
     */
    @Override
    public List<AdvertisingVO> selectByPositionId(Long positionId) {
        // 根据广告位ID获取该位置对应的广告详情
        List<AdvertisingPO> advertisings = baseMapper.selectByPositionId(positionId);

        // 转换成前端需要的数据
        return advertisings.stream().map(e -> {
            AdvertisingVO vo = new AdvertisingVO();
            BeanUtils.copyProperties(e, vo);

            vo.setAd_position_id(e.getAdPositionId())
                    .setMedia_type(e.getMediaType())
                    .setImage_url(e.getImageUrl())
                    .setEnd_time(e.getEndTime())
                    .setEnabled(e.getStatus());
            return vo;
        }).collect(Collectors.toList());
    }
}